package com.ruoyi.web.controller.market.source;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SourceDataHis;
import com.ruoyi.source.service.ISourceDataHisService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.SourceDataHisWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史表Controller
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@Controller
@RequestMapping("/source/his")
public class SourceDataHisController extends BaseController
{
    private String prefix = "source/his";

    @Autowired
    private ISourceDataHisService sourceDataHisService;

    @RequiresPermissions("source:his:view")
    @GetMapping()
    public String his()
    {
        return prefix + "/his";
    }

    /**
     * 查询历史表列表
     */
    @RequiresPermissions("source:his:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SourceDataHis sourceDataHis)
    {
        startPage();
        List<Map<String, Object>> mapList = sourceDataHisService.selectSourceDataHisListMap(sourceDataHis);
        mapList = new SourceDataHisWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出历史表列表
     */
    @RequiresPermissions("source:his:export")
    @Log(title = "历史表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SourceDataHis sourceDataHis)
    {
        List<SourceDataHis> list = sourceDataHisService.selectSourceDataHisList(sourceDataHis);
        ExcelUtil<SourceDataHis> util = new ExcelUtil<SourceDataHis>(SourceDataHis.class);
        return util.exportExcel(list, "历史表数据");
    }

    /**
     * 新增历史表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史表
     */
    @RequiresPermissions("source:his:add")
    @Log(title = "历史表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SourceDataHis sourceDataHis)
    {
        return toAjax(sourceDataHisService.insertSourceDataHis(sourceDataHis));
    }

    /**
     * 修改历史表
     */
    @RequiresPermissions("source:his:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SourceDataHis sourceDataHis = sourceDataHisService.selectSourceDataHisById(id);
        mmap.put("sourceDataHis", sourceDataHis);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史表
     */
    @RequiresPermissions("source:his:edit")
    @Log(title = "历史表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SourceDataHis sourceDataHis)
    {
        return toAjax(sourceDataHisService.updateSourceDataHis(sourceDataHis));
    }

    /**
     * 删除历史表
     */
    @RequiresPermissions("source:his:remove")
    @Log(title = "历史表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sourceDataHisService.deleteSourceDataHisByIds(ids));
    }
}
